local base = piece "base"
local pannel1 = piece "pannel1"
local pannel2 = piece "pannel2"
local pannels = piece "pannels"
local cylinder1 = piece "cylinder1"
local cylinder2 = piece "cylinder2"

local function openpannel(piece, sideturn)
        Turn(piece, z_axis, sideturn*-0.8, 0.5)
        WaitForTurn(piece, z_axis)    
        Turn(piece, z_axis, sideturn*-0.88, 0.3)
        WaitForTurn(piece, z_axis)   
        Turn(piece, z_axis, sideturn*-0.90, 0.2)
        WaitForTurn(piece, z_axis)
        Turn(piece, z_axis, sideturn*-0.92, 0.1)
end

local function Open()
        Signal(2)
        SetSignalMask(1)

	Move(pannels, y_axis, -10, 6)
	Spin(cylinder1, x_axis, 6, 0.05)
	Spin(cylinder2, x_axis, -6, 0.05)

	StartThread(openpannel, pannel1, 1)
	StartThread(openpannel, pannel2, -1)
        return true
end

local function Close()
        Signal(1)
        SetSignalMask(2)

	Move(pannels, y_axis, 0, 6)
	StopSpin(cylinder1, x_axis, 0.1)
	StopSpin(cylinder2, x_axis, 0.1)

	Turn(pannel1, z_axis, 0, 1)
	Turn(pannel2, z_axis, 0, 1)
        return true
end

function script.Activate ( )
        StartThread( Open )

end

function script.Deactivate ( )
        StartThread( Close )
end
